package ooday03;

public class RefArrayDemo {
    public static void main(String[] args) {
        Dog[] dogs = new Dog[3];//声明Dog[]行数组dogs，包三个元素，每个元素都是Dog型，默认值null
        Chick[] chicks = new Chick[2];
        Fish[] fishes = new Fish[2];
        dogs[0] = new Dog("小黑", 1, "白");
        dogs[1] = new Dog("小黑赖", 2, "银白");
        dogs[2] = new Dog("小黑头", 3, "金白");
        System.out.println(dogs[0].name);
        dogs[1].age = 4;//修改第二只狗的年龄
        for (int i = 0; i < dogs.length; i++) {
            System.out.println(dogs[i].name + "已经" + dogs[i].age + "岁了");
            dogs[i].swim();
        }
        chicks[0] = new Chick("大灰", 3, "黑");
        chicks[1] = new Chick("大灰灰", 1, "求黑");
        for (int i = 0; i < chicks.length; i++) {
            System.out.println(chicks[i].name + "已经" + dogs[i].age + "岁了");
            chicks[i].layEgg();
        }

        fishes[0] = new Fish("妖", 1, "银");
        fishes[1] = new Fish("妖妖", 2, "银金");
        for (int i = 0; i < fishes.length; i++) {
            System.out.println(fishes[i].name + "已经" + dogs[i].age + "岁了");
            fishes[i].swim();
        }
    }
}
